package com.gitee.cashzhang27.test.boot.crypt.plus.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import java.time.LocalDateTime;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/01/27 12:15
 */
@Slf4j
@Component
public class GlobalMetaObjectHandler implements MetaObjectHandler {

  @Override
  public void insertFill(MetaObject metaObject) {
    setFieldValByName("deleted", 0, metaObject);
    setFieldValByName("userCreate", "大娃", metaObject);
    setFieldValByName("gmtCreate", LocalDateTime.now(), metaObject);
  }

  @Override
  public void updateFill(MetaObject metaObject) {
    setFieldValByName("userModified", "二娃", metaObject);
    setFieldValByName("gmtModified", LocalDateTime.now(), metaObject);
  }
}
